package hh.leecode.doublepointer;


/**
 * 给一个已排序数组  【1,2,4,8】
 * 给一个和  10
 * 返回那两个数相加得到和
 */
public class 双指针_两数和 {
    public static void main(String[] args) {
        int[] arr = {0, 1, 2, 4, 8};

        String s = search1(arr, 11);
        System.out.println(s);


    }

    private static String search1(int[] arr, int target) {
        int leftIdx = 0;
        int rightIdx = arr.length - 1;

        while (true) {
            int sum = arr[leftIdx] + arr[rightIdx];
            if (sum == target) return leftIdx + " " + rightIdx;
            if (rightIdx - leftIdx <= 1) return "-1";

            if (sum > target) rightIdx--;
            if (sum < target) leftIdx++;


        }


    }
}
